package com.xmy.cultivate.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.xmy.cultivate.entity.Department;
import com.xmy.cultivate.entity.Station;
import com.xmy.cultivate.service.IDepartmentService;
import com.xmy.cultivate.util.Code;
import com.xmy.cultivate.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author hpiggy
 * @since 2025-01-01
 */
@RestController
@RequestMapping("/api/department")
public class DepartmentController {
    @Autowired
    IDepartmentService iDepartmentService;


    @GetMapping("")
    @ApiOperation("获取部门")
    public Result getDepartment(@RequestParam(value = "schoolId", required = false, defaultValue = "") String schoolId,
                                @RequestParam(value = "name", required = false, defaultValue = "") String name) {

        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(StringUtils.isNotBlank(schoolId), "school_id", schoolId);
        queryWrapper.like(StringUtils.isNotBlank(name), "name", name);
        queryWrapper.ne("status", 2);
        queryWrapper.orderByDesc("sort,id");

        List<Department> departmentList = iDepartmentService.list(queryWrapper);

        return new Result(Code.OK, departmentList, Code.GET_OK_MSG);
    }


    @GetMapping("/getDepartmentForResume")
    public Result getDepartmentForResume() {
        QueryWrapper<Department> queryWrapper = new QueryWrapper<>();
        queryWrapper.inSql("id", "SELECT department_id FROM adms_station_needs WHERE type = 2");
        List<Department> departmentList = iDepartmentService.list(queryWrapper);
        return new Result(Code.OK, departmentList, Code.GET_OK_MSG);
    }

}
